/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.capex.javacore.clases;

/**
 *
 * @author Acer
 */
public class Swap {

    int a, b;

    public static void main(String[] args) {
        Swap swap = new Swap(5,10);
        System.out.println(swap);
        swap.changeValues();
        System.out.println("Valores alternador. "+swap);

        int a[] = {1,2};
        System.out.println(a[0]+" "+a[1]);
        swap.changeValues(a);
        System.out.println("Valores cambiados por referencia. "+a[0]+" "+a[1]);

    }

    public Swap(int a, int b) {
        this.a = a;
        this.b = b;
    }

    public void changeValues() {
        int c = a;
        a = b;
        b = c;
    }

    public void changeValues(int a[]) {
        if (a.length == 2) {
            int c = a[0];
            a[0] = a[1];
            a[1] = c;
        }
    }

    @Override
    public String toString(){
        return "Valor a:"+a+" .Valor b:"+b;
    }

}
